/**
 * 
 */
package xj.toolkit.ebus.actors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import xj.toolkit.ebus.EventBus;


/**
 * @author hp
 *
 */
public class DefaultEventActor extends AbstractEventActor {

    private static final Logger logger = 
    	LoggerFactory.getLogger(DefaultEventActor.class);
    
    private Object      target;
    private Runnable	canceler;
    private String      event;
    private	String		method;
    
	public DefaultEventActor(EventBus ebus, String name) {
        super(ebus, name);
    }

    public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

    public Object getTarget() {
		return target;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	/**
     * @param event the event to set
     */
    public void setEvent(String event) {
        this.event = event.trim();
    }
    
	public String getEvent() {
		return event;
	}

	public void start() {
        canceler = registerObserver( event, target, method );
	}
	
    public void destroy() {
    	if ( null != canceler ) {
	        try {
	        	canceler.run();
	        } catch (Exception e) {
	        	logger.error("destroy:", e);
	        }
	        canceler = null;
    	}
        
        super.destroy();
    }

}
